package com.zyk.scaffold.components.holder;

import com.zyk.scaffold.common.utils.OptionalPlus;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationHolder implements ApplicationContextAware {

    private static volatile ApplicationContext applicationContext = null;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationHolder.applicationContext = applicationContext;
    }


    public static OptionalPlus<ApplicationContext> getApplicationContext() {
        return OptionalPlus.ofNullable(applicationContext);
    }
}
